<?php
/*
 * @Descripttion: 
 * @Author: 荷逸
 * @email: 563428234@qq.com
 * @Date: 2021-01-22 09:31:17
 */


namespace app\admin\model;

use driFile\File\Directory;
use driFile\File\Info;
use think\Exception;
use think\model\concern\SoftDelete;

class FilesDirectory extends Model
{
    private $dir;

    public function list()
    {
        try {

            $clsDirectory = new Directory($this->dir);
            // $clsDirectory->setDirectory( __DIR__ );
            $list = $clsDirectory->getList();
            if(empty($list)){
                return [];
            }
            foreach ($list as $detail) {
                $clsInfo = new Info($detail['path']);
                $data[] = [
                    'path' => str_replace('\\', '/',  $clsInfo->getPath()),
                    'type' => $clsInfo->getType(),
                    'base_name' => $clsInfo->getBaseName(),
                    'file_name' => $clsInfo->getFileName(),
                    // 'extension_name' => $clsInfo->getExtensionName(),
                    'size' =>  $clsInfo->getSize(),
                    'lastmod' =>  date('Y-m-d H:i:s', $clsInfo->getLastMod()),
                    'chmod' => $clsInfo->getChmod(),
                    // 'chown'=> $clsInfo->getChown()
                ];
            }
            return $data;

            //基本操作请看:https://symfony.com/doc/current/components/filesystem.html
            // $clsFile = new File();
            // echo 'file exists:' . $clsFile->exists(__DIR__ . DIRECTORY_SEPARATOR . 'index.php');
        } catch (Exception $e) {

            exception($e->getMessage());
        }
    }
    /**
     * Directory constructor.
     * @param string $directoryPath
     * @throws \Exception
     */
    public function __construct($directoryPath = '')
    {
        if (empty($directoryPath) ||  $directoryPath == '') {
            $this->dir = app()->getRootPath();
        } else {
            $this->dir = $directoryPath;
        }
    }


}
